<!-- 用户列表 -->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="20" :xs="24">
        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection" width="50" align="center" /> -->
          <el-table-column label="序号" type="index" width="50" />
          <el-table-column label="用户编号" align="center" key="id" prop="id" v-if="false" />
          <el-table-column label="用户名称" align="center" prop="account" width="120" />
          <el-table-column label="手机号码" align="center" prop="phone" width="120" />
          <el-table-column label="邮箱" align="center" prop="email" width="200" />

          <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.id != 1">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">查看</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
          @pagination="getList" />
      </el-col>
    </el-row>

    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
  
          <el-col :span="12">
            <el-form-item label="账号" prop="account">
              <el-input v-model="form.account" placeholder="请输入账号" maxlength="30" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户名" prop="realName">
              <el-input v-model="form.realName" placeholder="请输入用户名" maxlength="30" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="30" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机" maxlength="30" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">

      </div>
    </el-dialog>
  </div>
</template>
<script>

import { login, logout, getInfo, list, remove } from "@/api/user";
export default {
  name: "User",
  // 组件
  components: {},
  // 数据
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 用户表格数据
      list: [],
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
      },
      // 表单参数
      form: {},
      // 是否显示弹出层
      open: false,
    };
  },
  // 监听
  watch: {},
  // 构造函数
  created() {

    this.getList();
  },
  // 函数方法
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        // 后端返回
        console.log("userList", response);

        const data = response.data;
        this.list = data.records;
        this.total = data.total;
        this.loading = false;
      });
    },
    handleDelete(row) {
      const userIds = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除用户编号为"' + userIds + '"的数据项？')
        .then(function () {
          const data = {
            ids: userIds,
          };
          return remove(data);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    // 修改
    handleUpdate(row) {

      console.log('handleUpdate', row)
      this.open = true;
      this.form = row
      this.title = "查看";
    },

  },
};
</script>

<style scoped lang="scss"></style>
